<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Subjects extends CI_Controller {
	function __construct()
	{
		parent::__construct();
		$this->load->helper('url');
		$this->load->model('process_data');
		$this->load->model('adminsessions');

		if(!$this->adminsessions->isLogedIn()){
			redirect(base_url()."admin/home/login");
		}	
	}

	public function index($id=FALSE)
	{
		$data['mainSubjects'] = $this->process_data->get_main_subjects();
		$data['reqId'] = $id;
		if($id !== FALSE)	{
				
			$data['subjects'] = $this->process_data->get_subjectsMainsubject($id);
		}
		$this->load->view('admin/subjects/index', $data);
	}


	public function addMainSubject()
	{
		if(isset($_POST['addMemberPostData']))	{
			$this->process_data->addMainSubjects();
			redirect(base_url().'admin/subjects');
		}else{
			if(isset($_GET['id'])){
				$data['mainSubjects'] = $this->process_data->get_main_subjects($_GET['id']);
				$this->load->view('admin/subjects/addmainsubject', $data);
			}else {
				redirect(base_url().'admin/subjects');
			}
		}
	}
	public function addSubject()
	{
		if(isset($_POST['addMemberPostData']))	{
			$this->process_data->addSubjects();
			redirect(base_url().'admin/subjects');
		}else{
			if(isset($_GET['id']) && isset($_GET['mainSubject'])){
				$data['subjects'] = $this->process_data->get_subjects($_GET['id']);
				$this->load->view('admin/subjects/addsubject', $data);
			}else {
				redirect(base_url().'admin/subjects');
			}
		}
	}
}